{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "584b377c",
   "metadata": {},
   "source": [
    "______________\n",
    "\n",
    "* 2022/9/26/week06\n",
    "* Python学习记录\n",
    "______________"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a02eef11",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 随机函数\n",
    "\n",
    "> 2. 时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d7bc95e",
   "metadata": {},
   "source": [
    "## 1. 随机函数\n",
    "\n",
    "> 1. random.random(): 生成随机数，0-1之间随机函数\n",
    "> 2. random.randint(): 生成随机数\n",
    "> 3. random.choices(): 随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bf7ba13f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "17f79b00",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random:\n",
      "\n",
      "random() method of random.Random instance\n",
      "    random() -> x in the interval [0, 1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.random) # 0-1 float 小数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "666fc1c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4481404313222286"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "87866cc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.randint) # 整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e89802c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bdf12e2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "4\n",
      "1\n",
      "6\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "# randint小实践：大话骰\n",
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7142878a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# randint小实践：猜数字，0-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d0523d34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaohong'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.choice(),在数据组（列表）随机选择一个值\n",
    "random.choice([\"Alex\",\"Xiaohong\",\"Lihua\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "96d0c6ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18\n",
      "37\n",
      "23\n",
      "80\n",
      "18\n",
      "13\n"
     ]
    }
   ],
   "source": [
    "# 通过随机值，大概去判断一下彩票的中奖概率\n",
    "# [12,34,65,10,22,12]\n",
    "for i in range(6):\n",
    "    print(random.randint(0,99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee82f2c1",
   "metadata": {},
   "source": [
    "## 2. 时间函数 time()\n",
    "\n",
    "* 时间延迟函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "14f25e9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f9ecbbc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=26, tm_hour=10, tm_min=28, tm_sec=16, tm_wday=0, tm_yday=269, tm_isdst=0)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "27429bf0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4bb63dbc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "time.sleep(2)\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4eeb9b0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取...\n",
      "页面停留 31 秒\n",
      "继续下一页..\n"
     ]
    }
   ],
   "source": [
    "# 实践：浏览抓取网页数据，模拟人的行为，让机器慢下来，每执行一次休息3秒钟。\n",
    "#       进阶： 随机产生一个数（3，50），让程序停留随机秒数\n",
    "print(\"数据获取...\")\n",
    "wait_time = random.randint(3,50)\n",
    "print(\"页面停留\",wait_time,\"秒\")\n",
    "time.sleep(wait_time)\n",
    "print(\"继续下一页..\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6008a479",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取...\n",
      "页面停留 44 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 42 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 49 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 30 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 19 秒\n",
      "继续下一页..\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(\"数据获取...\")\n",
    "    wait_time = random.randint(3,50)\n",
    "    print(\"页面停留\",wait_time,\"秒\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"继续下一页..\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ad5d80e9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取...\n",
      "页面停留 6 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 5 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 3 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 7 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 7 秒\n",
      "继续下一页..\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(\"数据获取...\")\n",
    "    wait_time = random.randint(3,10)\n",
    "    print(\"页面停留\",wait_time,\"秒\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"继续下一页..\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "daf7e57e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据获取...\n",
      "页面停留 4 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 4 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 5 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 4 秒\n",
      "继续下一页..\n",
      "数据获取...\n",
      "页面停留 5 秒\n",
      "继续下一页..\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(\"数据获取...\")\n",
    "    wait_time = random.randint(3,5)\n",
    "    print(\"页面停留\",wait_time,\"秒\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"继续下一页..\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "31e9edbd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前是偶数秒\n",
      "等待时间（随机）： 4\n",
      "-------------\n",
      "当前是偶数秒\n",
      "等待时间（随机）： 3\n",
      "-------------\n",
      "当前是奇数秒\n",
      "等待时间（随机）： 2\n",
      "-------------\n",
      "当前是奇数秒\n",
      "等待时间（随机）： 5\n",
      "-------------\n",
      "当前是偶数秒\n",
      "等待时间（随机）： 3\n",
      "-------------\n"
     ]
    }
   ],
   "source": [
    "# from datetime import datetime\n",
    "import datetime\n",
    "import time,random\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_seconds = datetime.datetime.today().second\n",
    "    if right_this_seconds in odds:\n",
    "        print(\"当前是奇数秒\")\n",
    "    else:\n",
    "        print(\"当前是偶数秒\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    print(\"等待时间（随机）：\",wait_time)\n",
    "    time.sleep(wait_time)\n",
    "    print(\"-------------\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "26fce133",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles 在啤酒墙上~~\n",
      "99 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "98 bottles 在啤酒墙上~~\n",
      "----------\n",
      "98 bottles 在啤酒墙上~~\n",
      "98 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "97 bottles 在啤酒墙上~~\n",
      "----------\n",
      "97 bottles 在啤酒墙上~~\n",
      "97 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "96 bottles 在啤酒墙上~~\n",
      "----------\n",
      "96 bottles 在啤酒墙上~~\n",
      "96 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "95 bottles 在啤酒墙上~~\n",
      "----------\n",
      "95 bottles 在啤酒墙上~~\n",
      "95 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "94 bottles 在啤酒墙上~~\n",
      "----------\n",
      "94 bottles 在啤酒墙上~~\n",
      "94 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "93 bottles 在啤酒墙上~~\n",
      "----------\n",
      "93 bottles 在啤酒墙上~~\n",
      "93 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "92 bottles 在啤酒墙上~~\n",
      "----------\n",
      "92 bottles 在啤酒墙上~~\n",
      "92 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "91 bottles 在啤酒墙上~~\n",
      "----------\n",
      "91 bottles 在啤酒墙上~~\n",
      "91 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "90 bottles 在啤酒墙上~~\n",
      "----------\n",
      "90 bottles 在啤酒墙上~~\n",
      "90 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "89 bottles 在啤酒墙上~~\n",
      "----------\n",
      "89 bottles 在啤酒墙上~~\n",
      "89 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "88 bottles 在啤酒墙上~~\n",
      "----------\n",
      "88 bottles 在啤酒墙上~~\n",
      "88 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "87 bottles 在啤酒墙上~~\n",
      "----------\n",
      "87 bottles 在啤酒墙上~~\n",
      "87 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "86 bottles 在啤酒墙上~~\n",
      "----------\n",
      "86 bottles 在啤酒墙上~~\n",
      "86 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "85 bottles 在啤酒墙上~~\n",
      "----------\n",
      "85 bottles 在啤酒墙上~~\n",
      "85 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "84 bottles 在啤酒墙上~~\n",
      "----------\n",
      "84 bottles 在啤酒墙上~~\n",
      "84 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "83 bottles 在啤酒墙上~~\n",
      "----------\n",
      "83 bottles 在啤酒墙上~~\n",
      "83 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "82 bottles 在啤酒墙上~~\n",
      "----------\n",
      "82 bottles 在啤酒墙上~~\n",
      "82 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "81 bottles 在啤酒墙上~~\n",
      "----------\n",
      "81 bottles 在啤酒墙上~~\n",
      "81 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "80 bottles 在啤酒墙上~~\n",
      "----------\n",
      "80 bottles 在啤酒墙上~~\n",
      "80 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "79 bottles 在啤酒墙上~~\n",
      "----------\n",
      "79 bottles 在啤酒墙上~~\n",
      "79 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "78 bottles 在啤酒墙上~~\n",
      "----------\n",
      "78 bottles 在啤酒墙上~~\n",
      "78 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "77 bottles 在啤酒墙上~~\n",
      "----------\n",
      "77 bottles 在啤酒墙上~~\n",
      "77 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "76 bottles 在啤酒墙上~~\n",
      "----------\n",
      "76 bottles 在啤酒墙上~~\n",
      "76 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "75 bottles 在啤酒墙上~~\n",
      "----------\n",
      "75 bottles 在啤酒墙上~~\n",
      "75 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "74 bottles 在啤酒墙上~~\n",
      "----------\n",
      "74 bottles 在啤酒墙上~~\n",
      "74 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "73 bottles 在啤酒墙上~~\n",
      "----------\n",
      "73 bottles 在啤酒墙上~~\n",
      "73 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "72 bottles 在啤酒墙上~~\n",
      "----------\n",
      "72 bottles 在啤酒墙上~~\n",
      "72 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "71 bottles 在啤酒墙上~~\n",
      "----------\n",
      "71 bottles 在啤酒墙上~~\n",
      "71 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "70 bottles 在啤酒墙上~~\n",
      "----------\n",
      "70 bottles 在啤酒墙上~~\n",
      "70 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "69 bottles 在啤酒墙上~~\n",
      "----------\n",
      "69 bottles 在啤酒墙上~~\n",
      "69 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "68 bottles 在啤酒墙上~~\n",
      "----------\n",
      "68 bottles 在啤酒墙上~~\n",
      "68 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "67 bottles 在啤酒墙上~~\n",
      "----------\n",
      "67 bottles 在啤酒墙上~~\n",
      "67 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "66 bottles 在啤酒墙上~~\n",
      "----------\n",
      "66 bottles 在啤酒墙上~~\n",
      "66 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "65 bottles 在啤酒墙上~~\n",
      "----------\n",
      "65 bottles 在啤酒墙上~~\n",
      "65 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "64 bottles 在啤酒墙上~~\n",
      "----------\n",
      "64 bottles 在啤酒墙上~~\n",
      "64 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "63 bottles 在啤酒墙上~~\n",
      "----------\n",
      "63 bottles 在啤酒墙上~~\n",
      "63 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "62 bottles 在啤酒墙上~~\n",
      "----------\n",
      "62 bottles 在啤酒墙上~~\n",
      "62 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "61 bottles 在啤酒墙上~~\n",
      "----------\n",
      "61 bottles 在啤酒墙上~~\n",
      "61 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "60 bottles 在啤酒墙上~~\n",
      "----------\n",
      "60 bottles 在啤酒墙上~~\n",
      "60 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "59 bottles 在啤酒墙上~~\n",
      "----------\n",
      "59 bottles 在啤酒墙上~~\n",
      "59 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "58 bottles 在啤酒墙上~~\n",
      "----------\n",
      "58 bottles 在啤酒墙上~~\n",
      "58 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "57 bottles 在啤酒墙上~~\n",
      "----------\n",
      "57 bottles 在啤酒墙上~~\n",
      "57 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "56 bottles 在啤酒墙上~~\n",
      "----------\n",
      "56 bottles 在啤酒墙上~~\n",
      "56 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "55 bottles 在啤酒墙上~~\n",
      "----------\n",
      "55 bottles 在啤酒墙上~~\n",
      "55 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "54 bottles 在啤酒墙上~~\n",
      "----------\n",
      "54 bottles 在啤酒墙上~~\n",
      "54 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "53 bottles 在啤酒墙上~~\n",
      "----------\n",
      "53 bottles 在啤酒墙上~~\n",
      "53 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "52 bottles 在啤酒墙上~~\n",
      "----------\n",
      "52 bottles 在啤酒墙上~~\n",
      "52 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "51 bottles 在啤酒墙上~~\n",
      "----------\n",
      "51 bottles 在啤酒墙上~~\n",
      "51 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "50 bottles 在啤酒墙上~~\n",
      "----------\n",
      "50 bottles 在啤酒墙上~~\n",
      "50 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "49 bottles 在啤酒墙上~~\n",
      "----------\n",
      "49 bottles 在啤酒墙上~~\n",
      "49 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "48 bottles 在啤酒墙上~~\n",
      "----------\n",
      "48 bottles 在啤酒墙上~~\n",
      "48 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "47 bottles 在啤酒墙上~~\n",
      "----------\n",
      "47 bottles 在啤酒墙上~~\n",
      "47 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "46 bottles 在啤酒墙上~~\n",
      "----------\n",
      "46 bottles 在啤酒墙上~~\n",
      "46 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "45 bottles 在啤酒墙上~~\n",
      "----------\n",
      "45 bottles 在啤酒墙上~~\n",
      "45 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "44 bottles 在啤酒墙上~~\n",
      "----------\n",
      "44 bottles 在啤酒墙上~~\n",
      "44 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "43 bottles 在啤酒墙上~~\n",
      "----------\n",
      "43 bottles 在啤酒墙上~~\n",
      "43 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "42 bottles 在啤酒墙上~~\n",
      "----------\n",
      "42 bottles 在啤酒墙上~~\n",
      "42 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "41 bottles 在啤酒墙上~~\n",
      "----------\n",
      "41 bottles 在啤酒墙上~~\n",
      "41 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "40 bottles 在啤酒墙上~~\n",
      "----------\n",
      "40 bottles 在啤酒墙上~~\n",
      "40 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "39 bottles 在啤酒墙上~~\n",
      "----------\n",
      "39 bottles 在啤酒墙上~~\n",
      "39 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "38 bottles 在啤酒墙上~~\n",
      "----------\n",
      "38 bottles 在啤酒墙上~~\n",
      "38 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "37 bottles 在啤酒墙上~~\n",
      "----------\n",
      "37 bottles 在啤酒墙上~~\n",
      "37 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "36 bottles 在啤酒墙上~~\n",
      "----------\n",
      "36 bottles 在啤酒墙上~~\n",
      "36 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "35 bottles 在啤酒墙上~~\n",
      "----------\n",
      "35 bottles 在啤酒墙上~~\n",
      "35 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "34 bottles 在啤酒墙上~~\n",
      "----------\n",
      "34 bottles 在啤酒墙上~~\n",
      "34 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "33 bottles 在啤酒墙上~~\n",
      "----------\n",
      "33 bottles 在啤酒墙上~~\n",
      "33 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "32 bottles 在啤酒墙上~~\n",
      "----------\n",
      "32 bottles 在啤酒墙上~~\n",
      "32 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "31 bottles 在啤酒墙上~~\n",
      "----------\n",
      "31 bottles 在啤酒墙上~~\n",
      "31 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "30 bottles 在啤酒墙上~~\n",
      "----------\n",
      "30 bottles 在啤酒墙上~~\n",
      "30 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "29 bottles 在啤酒墙上~~\n",
      "----------\n",
      "29 bottles 在啤酒墙上~~\n",
      "29 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "28 bottles 在啤酒墙上~~\n",
      "----------\n",
      "28 bottles 在啤酒墙上~~\n",
      "28 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "27 bottles 在啤酒墙上~~\n",
      "----------\n",
      "27 bottles 在啤酒墙上~~\n",
      "27 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "26 bottles 在啤酒墙上~~\n",
      "----------\n",
      "26 bottles 在啤酒墙上~~\n",
      "26 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "25 bottles 在啤酒墙上~~\n",
      "----------\n",
      "25 bottles 在啤酒墙上~~\n",
      "25 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "24 bottles 在啤酒墙上~~\n",
      "----------\n",
      "24 bottles 在啤酒墙上~~\n",
      "24 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "23 bottles 在啤酒墙上~~\n",
      "----------\n",
      "23 bottles 在啤酒墙上~~\n",
      "23 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "22 bottles 在啤酒墙上~~\n",
      "----------\n",
      "22 bottles 在啤酒墙上~~\n",
      "22 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "21 bottles 在啤酒墙上~~\n",
      "----------\n",
      "21 bottles 在啤酒墙上~~\n",
      "21 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "20 bottles 在啤酒墙上~~\n",
      "----------\n",
      "20 bottles 在啤酒墙上~~\n",
      "20 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "19 bottles 在啤酒墙上~~\n",
      "----------\n",
      "19 bottles 在啤酒墙上~~\n",
      "19 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "18 bottles 在啤酒墙上~~\n",
      "----------\n",
      "18 bottles 在啤酒墙上~~\n",
      "18 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "17 bottles 在啤酒墙上~~\n",
      "----------\n",
      "17 bottles 在啤酒墙上~~\n",
      "17 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "16 bottles 在啤酒墙上~~\n",
      "----------\n",
      "16 bottles 在啤酒墙上~~\n",
      "16 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "15 bottles 在啤酒墙上~~\n",
      "----------\n",
      "15 bottles 在啤酒墙上~~\n",
      "15 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "14 bottles 在啤酒墙上~~\n",
      "----------\n",
      "14 bottles 在啤酒墙上~~\n",
      "14 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "13 bottles 在啤酒墙上~~\n",
      "----------\n",
      "13 bottles 在啤酒墙上~~\n",
      "13 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "12 bottles 在啤酒墙上~~\n",
      "----------\n",
      "12 bottles 在啤酒墙上~~\n",
      "12 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "11 bottles 在啤酒墙上~~\n",
      "----------\n",
      "11 bottles 在啤酒墙上~~\n",
      "11 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "10 bottles 在啤酒墙上~~\n",
      "----------\n",
      "10 bottles 在啤酒墙上~~\n",
      "10 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "9 bottles 在啤酒墙上~~\n",
      "----------\n",
      "9 bottles 在啤酒墙上~~\n",
      "9 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "8 bottles 在啤酒墙上~~\n",
      "----------\n",
      "8 bottles 在啤酒墙上~~\n",
      "8 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "7 bottles 在啤酒墙上~~\n",
      "----------\n",
      "7 bottles 在啤酒墙上~~\n",
      "7 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "6 bottles 在啤酒墙上~~\n",
      "----------\n",
      "6 bottles 在啤酒墙上~~\n",
      "6 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "5 bottles 在啤酒墙上~~\n",
      "----------\n",
      "5 bottles 在啤酒墙上~~\n",
      "5 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "4 bottles 在啤酒墙上~~\n",
      "----------\n",
      "4 bottles 在啤酒墙上~~\n",
      "4 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "3 bottles 在啤酒墙上~~\n",
      "----------\n",
      "3 bottles 在啤酒墙上~~\n",
      "3 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "2 bottles 在啤酒墙上~~\n",
      "----------\n",
      "2 bottles 在啤酒墙上~~\n",
      "2 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "1 bottles 在啤酒墙上~~\n",
      "----------\n",
      "1 bottles 在啤酒墙上~~\n",
      "1 bottles 啤酒~~\n",
      "拿下来一瓶给我吧~~\n",
      "啤酒被拿走一瓶了~~\n",
      "只剩下一瓶了，不能给你了，要放在墙上展示\n",
      "----------\n"
     ]
    }
   ],
   "source": [
    "beer_name = \"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,beer_name,\"在啤酒墙上~~\")\n",
    "    print(beer_num,beer_name,\"啤酒~~\")\n",
    "    print(\"拿下来一瓶给我吧~~\")\n",
    "    print(\"啤酒被拿走一瓶了~~\")\n",
    "    # 情况一：只剩一瓶的情况：\n",
    "    if beer_num == 1:\n",
    "        print(\"只剩下一瓶了，不能给你了，要放在墙上展示\")\n",
    "    # 情况二：还有多于一瓶的情况\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num ==1 :\n",
    "            beer_num = \"bottle\"\n",
    "        print(new_num,beer_name,\"在啤酒墙上~~\")\n",
    "    print(\"----------\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd93a5c3",
   "metadata": {},
   "source": [
    "## 3. 有序的数据结构（）\n",
    "> 1. 数值\n",
    ">> 1. [数值的运算]\n",
    "\n",
    "> 2. 字符串\n",
    "\n",
    "> 3. 列表，元组，字典，*集合  (期中考核) P144前"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "eead75f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "38b1180a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>运算</th>\n",
       "      <th>结果：</th>\n",
       "      <th>备注</th>\n",
       "      <th>完整文档</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>x + y</td>\n",
       "      <td>x 和 y 的和</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>x - y</td>\n",
       "      <td>x 和 y 的差</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>x * y</td>\n",
       "      <td>x 和 y 的乘积</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>x / y</td>\n",
       "      <td>x 和 y 的商</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>x // y</td>\n",
       "      <td>x 和 y 的商数</td>\n",
       "      <td>(1)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>x % y</td>\n",
       "      <td>x / y 的余数</td>\n",
       "      <td>(2)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-x</td>\n",
       "      <td>x 取反</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>+x</td>\n",
       "      <td>x 不变</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>abs(x)</td>\n",
       "      <td>x 的绝对值或大小</td>\n",
       "      <td>NaN</td>\n",
       "      <td>abs()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>int(x)</td>\n",
       "      <td>将 x 转换为整数</td>\n",
       "      <td>(3)(6)</td>\n",
       "      <td>int()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>float(x)</td>\n",
       "      <td>将 x 转换为浮点数</td>\n",
       "      <td>(4)(6)</td>\n",
       "      <td>float()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>complex(re, im)</td>\n",
       "      <td>一个带有实部 re 和虚部 im 的复数。im 默认为0。</td>\n",
       "      <td>(6)</td>\n",
       "      <td>complex()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>c.conjugate()</td>\n",
       "      <td>复数 c 的共轭</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>divmod(x, y)</td>\n",
       "      <td>(x // y, x % y)</td>\n",
       "      <td>(2)</td>\n",
       "      <td>divmod()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>pow(x, y)</td>\n",
       "      <td>x 的 y 次幂</td>\n",
       "      <td>(5)</td>\n",
       "      <td>pow()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>x ** y</td>\n",
       "      <td>x 的 y 次幂</td>\n",
       "      <td>(5)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 运算                            结果：      备注       完整文档\n",
       "0             x + y                       x 和 y 的和     NaN        NaN\n",
       "1             x - y                       x 和 y 的差     NaN        NaN\n",
       "2             x * y                      x 和 y 的乘积     NaN        NaN\n",
       "3             x / y                       x 和 y 的商     NaN        NaN\n",
       "4            x // y                      x 和 y 的商数     (1)        NaN\n",
       "5             x % y                      x / y 的余数     (2)        NaN\n",
       "6                -x                           x 取反     NaN        NaN\n",
       "7                +x                           x 不变     NaN        NaN\n",
       "8            abs(x)                      x 的绝对值或大小     NaN      abs()\n",
       "9            int(x)                      将 x 转换为整数  (3)(6)      int()\n",
       "10         float(x)                     将 x 转换为浮点数  (4)(6)    float()\n",
       "11  complex(re, im)  一个带有实部 re 和虚部 im 的复数。im 默认为0。     (6)  complex()\n",
       "12    c.conjugate()                       复数 c 的共轭     NaN        NaN\n",
       "13     divmod(x, y)                (x // y, x % y)     (2)   divmod()\n",
       "14        pow(x, y)                       x 的 y 次幂     (5)      pow()\n",
       "15           x ** y                       x 的 y 次幂     (5)        NaN"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"https://docs.python.org/zh-cn/3/library/stdtypes.html#numeric-types-int-float-complex\")[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5db41b3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 3.0 数值的类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b2743ae5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### 3.1 数值的基本运算（operation）\n",
    "\n",
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "080f41c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1a9e78de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.25"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "778fe6e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//4  # 取整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "1d9bde64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17%5  # 取余数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "2fcabd89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "4a524587",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.23606797749979"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**(1/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "47e53a6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2&3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01a03b6e",
   "metadata": {},
   "source": [
    "### 3.2 数值的一般方法（Methods）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "2e189add",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\\x00'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1024).to_bytes(10, byteorder='big')     ##  bytes 类型的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "f3f31fbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(2.5).is_integer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d469f37c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2.0.is_integer()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "080c1b89",
   "metadata": {},
   "source": [
    "## 4.字符串\n",
    "\n",
    "* 课后\n",
    "> 1. 什么是字符串？\n",
    "> 2. 字符串的一般表示形式\n",
    "> 3. 字符串的运算有哪些？  譬如：+ 是什么意思, 取值，切片，索引的概念是什么？\n",
    "> 4. 字符串的一般方法？  譬如：count(), in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0340719e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#! pip install imageio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e1b9a451",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'jieba'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mjieba\u001b[39;00m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mwordcloud\u001b[39;00m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mimageio\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'jieba'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import jieba\n",
    "import wordcloud\n",
    "import imageio\n",
    "from collections import Counter\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a4459f8f",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: '/home/kesci/input/kfca8585/kfc.csv'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_csv\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/home/kesci/input/kfca8585/kfc.csv\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m data\u001b[38;5;241m.\u001b[39mhead()\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\util\\_decorators.py:311\u001b[0m, in \u001b[0;36mdeprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    305\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m>\u001b[39m num_allow_args:\n\u001b[0;32m    306\u001b[0m     warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[0;32m    307\u001b[0m         msg\u001b[38;5;241m.\u001b[39mformat(arguments\u001b[38;5;241m=\u001b[39marguments),\n\u001b[0;32m    308\u001b[0m         \u001b[38;5;167;01mFutureWarning\u001b[39;00m,\n\u001b[0;32m    309\u001b[0m         stacklevel\u001b[38;5;241m=\u001b[39mstacklevel,\n\u001b[0;32m    310\u001b[0m     )\n\u001b[1;32m--> 311\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\io\\parsers\\readers.py:680\u001b[0m, in \u001b[0;36mread_csv\u001b[1;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)\u001b[0m\n\u001b[0;32m    665\u001b[0m kwds_defaults \u001b[38;5;241m=\u001b[39m _refine_defaults_read(\n\u001b[0;32m    666\u001b[0m     dialect,\n\u001b[0;32m    667\u001b[0m     delimiter,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    676\u001b[0m     defaults\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdelimiter\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m,\u001b[39m\u001b[38;5;124m\"\u001b[39m},\n\u001b[0;32m    677\u001b[0m )\n\u001b[0;32m    678\u001b[0m kwds\u001b[38;5;241m.\u001b[39mupdate(kwds_defaults)\n\u001b[1;32m--> 680\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_read\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\io\\parsers\\readers.py:575\u001b[0m, in \u001b[0;36m_read\u001b[1;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[0;32m    572\u001b[0m _validate_names(kwds\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnames\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m))\n\u001b[0;32m    574\u001b[0m \u001b[38;5;66;03m# Create the parser.\u001b[39;00m\n\u001b[1;32m--> 575\u001b[0m parser \u001b[38;5;241m=\u001b[39m TextFileReader(filepath_or_buffer, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds)\n\u001b[0;32m    577\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chunksize \u001b[38;5;129;01mor\u001b[39;00m iterator:\n\u001b[0;32m    578\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m parser\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\io\\parsers\\readers.py:933\u001b[0m, in \u001b[0;36mTextFileReader.__init__\u001b[1;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[0;32m    930\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m kwds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m    932\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles: IOHandles \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m--> 933\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_engine\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mengine\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\io\\parsers\\readers.py:1217\u001b[0m, in \u001b[0;36mTextFileReader._make_engine\u001b[1;34m(self, f, engine)\u001b[0m\n\u001b[0;32m   1213\u001b[0m     mode \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrb\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1214\u001b[0m \u001b[38;5;66;03m# error: No overload variant of \"get_handle\" matches argument types\u001b[39;00m\n\u001b[0;32m   1215\u001b[0m \u001b[38;5;66;03m# \"Union[str, PathLike[str], ReadCsvBuffer[bytes], ReadCsvBuffer[str]]\"\u001b[39;00m\n\u001b[0;32m   1216\u001b[0m \u001b[38;5;66;03m# , \"str\", \"bool\", \"Any\", \"Any\", \"Any\", \"Any\", \"Any\"\u001b[39;00m\n\u001b[1;32m-> 1217\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;241m=\u001b[39m \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43m  \u001b[49m\u001b[38;5;66;43;03m# type: ignore[call-overload]\u001b[39;49;00m\n\u001b[0;32m   1218\u001b[0m \u001b[43m    \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1219\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1220\u001b[0m \u001b[43m    \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1221\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcompression\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1222\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmemory_map\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmemory_map\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1223\u001b[0m \u001b[43m    \u001b[49m\u001b[43mis_text\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mis_text\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1224\u001b[0m \u001b[43m    \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding_errors\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstrict\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1225\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstorage_options\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1226\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1227\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m   1228\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles\u001b[38;5;241m.\u001b[39mhandle\n",
      "File \u001b[1;32mD:\\Users\\pc\\anaconda3\\lib\\site-packages\\pandas\\io\\common.py:789\u001b[0m, in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m    784\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(handle, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m    785\u001b[0m     \u001b[38;5;66;03m# Check whether the filename is to be opened in binary mode.\u001b[39;00m\n\u001b[0;32m    786\u001b[0m     \u001b[38;5;66;03m# Binary mode does not support 'encoding' and 'newline'.\u001b[39;00m\n\u001b[0;32m    787\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mencoding \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mmode:\n\u001b[0;32m    788\u001b[0m         \u001b[38;5;66;03m# Encoding\u001b[39;00m\n\u001b[1;32m--> 789\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[0;32m    790\u001b[0m \u001b[43m            \u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    791\u001b[0m \u001b[43m            \u001b[49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    792\u001b[0m \u001b[43m            \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    793\u001b[0m \u001b[43m            \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    794\u001b[0m \u001b[43m            \u001b[49m\u001b[43mnewline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m    795\u001b[0m \u001b[43m        \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    796\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    797\u001b[0m         \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[0;32m    798\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(handle, ioargs\u001b[38;5;241m.\u001b[39mmode)\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/home/kesci/input/kfca8585/kfc.csv'"
     ]
    }
   ],
   "source": [
    "data = pd.read_csv('/home/kesci/input/kfca8585/kfc.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8f6d2cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02ade008",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a6c74e3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
